package models

import orm "go-admin/common/global"

/**
* @Description:
* @Author: yuweizhu
* @Date: 2020/11/22 10:26 下午
**/
type TRightsConfig struct {
	ID      int    `json:"id"`
	Value   int64  `json:"value"`
	Costs   int `json:"costs"`
	Product string `json:"products"`
}

func (TRightsConfig) TableName() string {
	return "t_rights_config"
}

func (e *TRightsConfig) Get() (config *TRightsConfig, err error) {

	table := orm.GetDb().Table(e.TableName()).Select([]string{"t_rights_config.*"})
	if e.ID != 0 {
		table = table.Where("id = ?", e.ID)
	}

	var res TRightsConfig
	if err = table.Debug().First(&res).Error; err != nil {
		return
	}
	config = &res
	return
}

func (e *TRightsConfig) GetAll() (config []TRightsConfig) {

	table := orm.GetDb().Table(e.TableName()).Select([]string{"t_rights_config.*"})
	_ = table.Find(&config).Error
	return config
}
